def print_logo():
    print(r"""
    _                             ____
   / | ___ ___ ___  ___ ___  ___ |  _ \
  /  |/ __/ __/ _ \/ __/ __|/ _ \| |_) |
 / - | (_| (_|  __/\__ \__ \ (_) |  _ <
/_||_|\___\___\___||___/___/\___/|_| \_\

        UNSTABLE        CORE v0.1
                by Allowri
""")


def try_get_int(text: str, default=None) -> int:
    while True:
        ret = input(text)

        if not ret:
            if default:
                return default

        if ret.isdigit():
            return int(ret)

        else:
            print("Incorrect input")


def drop_config(file_path, **kwargs):
    with open(file_path, "w+") as config:
        for key, value in kwargs.items():
            if isinstance(value, int):
                config.write(f"{key.upper()} = {value}\n")

            elif isinstance(value, str):
                config.write(f'{key.upper()} = "{value}"\n')

            else:
                raise TypeError("Type nit support! (Only: int, str)")

    print(f"\n[!] File has been saved to {file_path}\n")

def configurator():
    print_logo()

    print("\n\tCommon settings:\n")
    packet_size = try_get_int("Packet size (default: 2048): ", 2048)
    reconnect_time = try_get_int("Reconnect time (defaul: 25): ", 25)
    port = try_get_int("Port (default: 9090): ", 9090)


    print("\n\tClient settings:\n")
    ip = input("Server IP: ")

    drop_config("Client/config.py",
        packet_size=packet_size,
        reconnect_time=reconnect_time,
        port=port,
        ip=ip)
    

if __name__ == "__main__":
    configurator()
